package com.hua.designpattern.behavioral.chainofresponsibility;

public abstract class AbstractLogger {
	public static int ALL = 0;
	public static int INFO = 1;
	public static int WARN = 2;
	public static int ERROR = 3;
	public static int FATAL = 4;

	private int level = -1;

	public AbstractLogger(int level) {
		this.level = level;
	}

	private AbstractLogger nextLogger;

	public void logMessage(int level, String message) {
		if (this.level <= level) {
			write(message);
			return;
		}
		if (nextLogger != null) {
			nextLogger.logMessage(level, message);
		} else {
			System.out.println("unhandle log!!");
		}
	}

	abstract protected void write(String message);

	public AbstractLogger getNextLogger() {
		return nextLogger;
	}

	public void setNextLogger(AbstractLogger nextLogger) {
		this.nextLogger = nextLogger;
	}

}
